import { BrowserWindow, ipcMain } from "electron";

let settingWindow;
const winURL =
	process.env.NODE_ENV === "development"
		? `http://localhost:9080`
		: `file://${__dirname}/index.html`;

const setting = () => {
	settingWindow = new BrowserWindow({
		width: 580,
		height: 440,
		useContentSize: true,
		// 双击放大
		maximizable: false,
		// 是否可缩放
		resizable: false,
		// 是否置顶
		alwaysOnTop: true,
		// 最小高度
		minHeight: 440,
		// 最小宽度
		minWidth: 580,
		// 窗口居中
		center: true,
		// 隐藏菜单栏
		autoHideMenuBar: true,
		frame: false,
		transparent: true,
		webPreferences: {
			// 是否打开调试控制台
			devTools: false,
			enablemotemodule: true,
			nodeIntegration: true,
			// 不拦截跨域
			webSecurity: false,
		},
	});

	settingWindow.loadURL(winURL + "#/setting");

	settingWindow.on("closed", () => {
		settingWindow = null;
	});
};

ipcMain.on("setting-close", () => {
	settingWindow.close();
});
ipcMain.on("setting-minimize", () => {
	settingWindow.minimize();
});
ipcMain.on("setting-maximize", (e, val) => {
	val ? settingWindow.unmaximize() : settingWindow.maximize();
});

export default setting;
